using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace WIT.DAQ.Core.Forms.UserControls;

/// <summary>
///
/// </summary>
internal class UC_DeviceParams_For_S7 : UserControl
{
	/// <summary>
	/// 机架号
	/// </summary>
	internal int RACK = 0;

	/// <summary>
	/// 插槽号
	/// </summary>
	internal int SLOT = 1;

	/// <summary> 
	/// 必需的设计器变量。
	/// </summary>
	private IContainer components = null;

	private TextBox txtSlot;

	private TextBox txtRack;

	private Label label4;

	private Label label3;

	private Label label6;

	private Label label8;

	/// <summary>
	///
	/// </summary>
	internal UC_DeviceParams_For_S7()
	{
		InitializeComponent();
	}

	/// <summary>
	///
	/// </summary>
	/// <param name="rack">机架号</param>
	/// <param name="slot">插槽号</param>
	internal UC_DeviceParams_For_S7(int? rack, int? slot)
	{
		InitializeComponent();
		if (rack.HasValue)
		{
			RACK = rack.Value;
		}
		if (slot.HasValue)
		{
			SLOT = slot.Value;
		}
	}

	private void UC_DeviceParams_For_S7_Load(object sender, EventArgs e)
	{
		txtRack.Text = RACK.ToString();
		txtSlot.Text = SLOT.ToString();
	}

	/// <summary>
	/// 校验输入的内容是否合法
	/// </summary>
	/// <returns></returns>
	internal bool ValidateInputs(out string msg)
	{
		msg = string.Empty;
		bool flag = false;
		try
		{
			if (!int.TryParse(txtRack.Text.Trim(), out RACK))
			{
				throw new Exception("机架号格式不正确");
			}
			if (!int.TryParse(txtSlot.Text.Trim(), out SLOT))
			{
				throw new Exception("插槽号格式不正确");
			}
			flag = true;
		}
		catch (Exception ex)
		{
			flag = false;
			msg = ex.Message;
		}
		return flag;
	}

	/// <summary> 
	/// 清理所有正在使用的资源。
	/// </summary>
	/// <param name="disposing">如果应释放托管资源，为 true；否则为 false。</param>
	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	/// <summary> 
	/// 设计器支持所需的方法 - 不要修改
	/// 使用代码编辑器修改此方法的内容。
	/// </summary>
	private void InitializeComponent()
	{
		this.txtSlot = new System.Windows.Forms.TextBox();
		this.txtRack = new System.Windows.Forms.TextBox();
		this.label4 = new System.Windows.Forms.Label();
		this.label3 = new System.Windows.Forms.Label();
		this.label6 = new System.Windows.Forms.Label();
		this.label8 = new System.Windows.Forms.Label();
		base.SuspendLayout();
		this.txtSlot.Location = new System.Drawing.Point(121, 57);
		this.txtSlot.Name = "txtSlot";
		this.txtSlot.Size = new System.Drawing.Size(121, 21);
		this.txtSlot.TabIndex = 1;
		this.txtRack.Location = new System.Drawing.Point(121, 30);
		this.txtRack.Name = "txtRack";
		this.txtRack.Size = new System.Drawing.Size(121, 21);
		this.txtRack.TabIndex = 0;
		this.label4.AutoSize = true;
		this.label4.Location = new System.Drawing.Point(32, 60);
		this.label4.Name = "label4";
		this.label4.Size = new System.Drawing.Size(83, 12);
		this.label4.TabIndex = 13;
		this.label4.Text = "Slot(插槽号):";
		this.label3.AutoSize = true;
		this.label3.Location = new System.Drawing.Point(32, 33);
		this.label3.Name = "label3";
		this.label3.Size = new System.Drawing.Size(83, 12);
		this.label3.TabIndex = 14;
		this.label3.Text = "Rack(机架号):";
		this.label6.AutoSize = true;
		this.label6.ForeColor = System.Drawing.Color.Red;
		this.label6.Location = new System.Drawing.Point(248, 33);
		this.label6.Name = "label6";
		this.label6.Size = new System.Drawing.Size(17, 12);
		this.label6.TabIndex = 21;
		this.label6.Text = "* ";
		this.label8.AutoSize = true;
		this.label8.ForeColor = System.Drawing.Color.Red;
		this.label8.Location = new System.Drawing.Point(248, 60);
		this.label8.Name = "label8";
		this.label8.Size = new System.Drawing.Size(17, 12);
		this.label8.TabIndex = 21;
		this.label8.Text = "* ";
		base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 12f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.Controls.Add(this.label8);
		base.Controls.Add(this.label6);
		base.Controls.Add(this.txtSlot);
		base.Controls.Add(this.txtRack);
		base.Controls.Add(this.label4);
		base.Controls.Add(this.label3);
		base.Name = "UC_DeviceParams_For_S7";
		base.Size = new System.Drawing.Size(523, 165);
		base.Load += new System.EventHandler(UC_DeviceParams_For_S7_Load);
		base.ResumeLayout(false);
		base.PerformLayout();
	}
}
